import pymysql
def save_mysql(sql,val,**dbinfo):
    try:
        connect=pymysql.connect(**dbinfo)
        cursor=connect.cursor()
        cursor.executemany(sql,val)
        connect.commit()
    except Exception as e:
        connect.rollback
        print(e)
    finally:
        cursor.close()
        connect.close()
if __name__ == '__main__':
    data={
        "host":"127.0.0.1",
        "user":"root",
        "password":"root",
        "db":"wo",
        "charset":"utf8",
        "cursorclass":pymysql.cursors.DictCursor
    }
    sql="insert into teacherinfo(tno,tname) values(%s,%s)"
    values=[["2500","王建硕"],["2501","梁志超"]]
    save_mysql(sql,values,**data)